﻿using System.Collections.Generic;

/// <summary>
/// This struct serves as a container for combo-key input relevant information
/// </summary>
struct KeyEntry
{
    public KeyEntry(InputKey key, float frameStamp, float deltaStamp)
    {
        Key = key;
        FrameStamp = frameStamp;
        DeltaFrameStamp = deltaStamp;
    }
    // Used Key
    public InputKey Key;
    // Frame in which the key was pressed
    public float FrameStamp;
    // Precalculated delta to last entry
    public float DeltaFrameStamp;
}

/// <summary>
/// This class stores user input to check if a combo was made
/// </summary>
class KeyEntryList : List<KeyEntry>
{
    private int _maxCount;
    private ComboDefineList _comboDefines;

    /// <param name="combos">Holds the combos a character can do</param>
    /// <param name="maxCount">Determines the maximal amount of entries the combolist can hold</param>
    public KeyEntryList(ref ComboDefineList combos, int maxCount = 10)
    {
        _maxCount = maxCount;
        _comboDefines = combos;
    }

    public void AddNew(InputKey key, float frameStamp)
    {
        // Calculate delta to last entry
        float delta = 0;
        if (this.Count > 0)
        {
            delta = frameStamp - this[0].FrameStamp;
        }

        // Insert item at first position
        this.Insert(0, new KeyEntry(key, frameStamp, delta));

        // Check if count is above maximum
        if (this.Count > _maxCount)
        {
            this.RemoveAt(this.Count - 1);
        }

        // Check for combos
        CheckCombo();
    }

    /// <summary>
    /// This method checks if the user has just finished a combo-sequence
    /// </summary>
    private void CheckCombo()
    {
        // Check recursvively for combos
        foreach (ComboDefine cd in _comboDefines.Items)
        {
            
        }
        
    }

    /// <summary>
    /// Debug method to print out the current entries in the list
    /// </summary>
    public string Print()
    {
        string ret = this.Count + "\n";
        KeyEntry c;
        for(int i = this.Count - 1; i >= 0; --i)
        {
            c = this[i];
            ret += ":" + c.Key.ToString() + "\n";
        }
        return ret;
    }

}